using Microsoft.Extensions.Options;
using MongoDB.Driver;

using newApi.Models;
namespace newApi.Services;

public class ChanelsService
{
    private readonly IMongoCollection<Chanel> _ChanelCollection;

    public ChanelsService(IOptions<NewsLibDatabaseSettings> newsLibDatabaseSettings)
    {
         var mongoClient = new MongoClient(
            newsLibDatabaseSettings.Value.ConnectionString);

        var mongoDatabase = mongoClient.GetDatabase(
            newsLibDatabaseSettings.Value.DatabaseName);

        _ChanelCollection = mongoDatabase.GetCollection<Chanel>(
            newsLibDatabaseSettings.Value.ChanelsCollectionName);
    }

    public async Task<List<Chanel>> GetAsync() =>
        await _ChanelCollection.Find(_ => true).ToListAsync();

    internal Task UpdateAsync(string id, Chanel updatedChanel)
    {
        throw new NotImplementedException();
    }

    public async Task<List<Chanel>> GetAsync(string id) =>
     await _ChanelCollection.Find(_=> true).ToListAsync();

     public async Task CreateChanel(Chanel newChanel) =>
        await _ChanelCollection.InsertOneAsync(newChanel);

    internal Task CreateAsyn(Chanel newChanel)
    {
        throw new NotImplementedException();
    }

    // internal Task UpdateAsync(string id, Chanel updatedChanel)
    // {
    //     throw new NotImplementedException();
    // }

    internal Task RemoveAsync(string id)
    {
        throw new NotImplementedException();
    }
}